{% extends "cmdb/mbusiness/index.html" %}

{% block right_content %}
<div id="right_menu">
    <div>
        <button id="add" class="btn btn-info hint hint-top" data-hint="添加一个业务分类信息" style="float:left;margin-bottom: 15px;"><span class="glyphicon glyphicon-plus"></span></button>

        <form class="form-inline" style="float: right">
            <div class="form-group">
                <label class="sr-only" for="search">Search</label>
                <input type="search" class="form-control" id="search" placeholder="分类名" value="{{ search }}" style="width:100%">
            </div>
            <button type="button" class="btn btn-primary" id="searchCategory"><span class="glyphicon glyphicon-search"></span></button>
        </form>
    </div>
    <table id="example" style="table-layout:fixed;" class="table table-bordered table-hover">
        <thead >
            <td class="col">分类id</td>
            <td class="col">分类名</td>
            <td class="col">分类级别</td>
            <td class="col">父类别</td>
            <td class="col">操作</td>
        </thead>
        {% if category_list %}
        {% for category in category_list %}
        <tr>
            <td class="col">{{ category.id }}</td>
            {% ifequal category.grade 2 %}
            <td class="col"><a  href="{% url 'business:moduleinfo' %}?category={{ category.id }}">{{ category.category_name }}</a></td>
            {% else %}
            <td class="col">{{ category.category_name }}</td>
            {% endifequal %}
            <td class="col">{{ category.category_level }}</td>
            <td class="col">{{ category.parent_category_name }}</td>
            <td class="col">
                <div>
                    <a  class="edit_item hint hint-top mouse_pointer" data-hint="编辑分类信息" data-id="{{ category.id }}" data-toggle="modal" data-target="#editItem">
                        <span class="glyphicon glyphicon-edit"></span>
                    </a>&nbsp;
                    <a data-id="{{ category.id }}" data-grade="{{ category.grade }}" class="delete_item hint hint-top mouse_pointer" data-hint="删除分类信息">
                        <span class="glyphicon glyphicon-trash"></span>
                    </a>
                </div>
            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div>
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>
        <span style="float:right;padding-right:50px">
            <a class="word hint hint-top" data-hint="首页" href="{% url 'business:home' %}?page=1&search={{ search }}"><span class="glyphicon glyphicon-fast-backward"></span></a>
            {% ifnotequal page 1 %}&nbsp;
            <a class="hint hint-top" data-hint="上一页" href="{% url 'business:home' %}?page={{ page|add:-1 }}&search={{ search }}"><span class="glyphicon glyphicon-step-backward"></span></a>
            {% endifnotequal %}
            {% ifnotequal page page_total %}&nbsp;
            <a class="hint hint-top" data-hint="下一页" href="{% url  'business:home' %}?page={{ page|add:1 }}&search={{ search }}"><span class="glyphicon glyphicon-step-forward"></span></a>
            {% endifnotequal %}&nbsp;
            <a class="word hint hint-top" data-hint="尾页" href="{% url 'business:home' %}?page={{ page_total }}&search={{ search }}"><span class="glyphicon glyphicon-fast-forward"></span></a>
        </span>
    </div>
</div>

<script type="text/javascript">
$(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        window.location.href="{% url 'business:home' %}?page=" + index + "&&search={{ search }}";
});
$("#add").click(function(){
    window.location.href="{% url 'business:caddinfo' %}";
});
$(".edit_item").click(function(){
    var id = $(this).data("id");
    var page= $(this).data("page");
    window.location.href="{% url 'business:ceditinfo' %}?page="+{{ page }}+"&id="+id;
});
$(".delete_item").click(function(){
    if(confirm("确定要删除吗？删除操作不可恢复！")) {
        var id = $(this).data("id");
        var grade = $(this).data("grade");
        var urls = "{% url 'business:cdeleteaction' %}";
        var postdata = {id:id, grade:grade}
        var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		});
		var jsonobj = eval('(' + jsonstr.responseText + ')');
		if(jsonobj.status == 0){
	        alert(jsonobj.message);
	    }else{
	        window.location.reload();
	    }
    }
});

$("#searchCategory").click(function(){
    var search = $("#search").val();
    window.location.href="{% url 'business:home' %}?page=" + {{ page }} + "&search=" + search;
});
</script>
{% endblock  %}

